package com.system.couponserver.controller;

import com.system.couponserver.pojo.Coupon;
import com.system.couponserver.service.CouponService;
import com.system.couponserver.utils.Constant;
import com.system.couponserver.utils.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mapstruct.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(value = "优惠卷",tags = "优惠卷")
@RequestMapping(value = "cp")
public class CouponController {
    @Autowired
    private CouponService couponService;

    /**
     * 查询所有
     */
    @RequestMapping(value = "/query01.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "优惠卷查询接口",notes = "查询优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public ResultData query01(@RequestBody Coupon coupon){
        System.out.println(coupon.getCurrentPsge());
        System.out.println(coupon.getPageSize());
        ResultData resultData = couponService.query01(coupon.getCurrentPsge(),coupon.getPageSize());
        return resultData;
    }

    /**
     * 条件查询  通过名字 id
     * @param coupon
     * @return
     */
    @RequestMapping(value = "/query02.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "优惠卷查询通过名字 id接口",notes = "通过名字 id查询优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public ResultData query03(@RequestBody Coupon coupon){
        System.out.println(coupon.getCurrentPsge());
        System.out.println(coupon.getPageSize());
        ResultData resultData = couponService.query03(coupon);
        return resultData;
    }

    /**
     * 新增优惠卷
     */
    @RequestMapping(value = "/query03.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增优惠卷查询接口",notes = "新增优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public ResultData query04(@RequestBody Coupon coupon){
        //coupon_name,coupon_number,coupon_startMoney,
        // coupon_money,coupon_startTime,coupon_endTime,coupon_statue
        Double Coupon_Startmoney = coupon.getCoupon_Startmoney();
        Double Coupon_Money =  coupon.getCoupon_Money();
        ResultData resultData = new ResultData();
        if(coupon.getCoupon_name() != null
                && coupon.getCoupon_Number() != null
                && coupon.getCoupon_Endtime() != null
                && Coupon_Startmoney != null
                && Coupon_Money != null
                && Coupon_Startmoney > 0
                && Coupon_Money > 0
                && coupon.getCoupon_Endtime() !=null
                && coupon.getCoupon_Starttime() != null){
            int result = couponService.query04(coupon);
            if(result > 0 ){
                resultData.setCode(Constant.CODE_STATUS_SUCCESS);
                resultData.setMessage("新增优惠卷成功");
            } else {
                resultData.setCode(Constant.CODE_STATUS_FAILURE);
                resultData.setMessage("新增优惠卷失败");
            }
            return resultData;
        }else {
            resultData.setMessage("新增优惠卷失败");
        }
        resultData.setMessage("新增优惠卷失败");
        return resultData;
    }

    /**
     * 查看详情
     */
    @RequestMapping(value = "/query04.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查看详情优惠卷查询接口",notes = "查看详情优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public ResultData query05(@RequestBody Coupon coupon){
        System.out.println(coupon.getCurrentPsge());
        System.out.println(coupon.getPageSize());
        ResultData resultData = couponService.query05(coupon);
        return resultData;
    }

    /**
     * 编辑修改
     */
    @RequestMapping(value = "/query05.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改优惠卷查询接口",notes = "修改查询优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public ResultData query06(@RequestBody Coupon coupon){
        int result = couponService.query06(coupon);
        ResultData resultData = new ResultData();
        if(result > 0){
            resultData.setCode(Constant.CODE_STATUS_SUCCESS);
            resultData.setMessage("修改优惠卷成功");
        } else {
            resultData.setCode(Constant.CODE_STATUS_FAILURE);
            resultData.setMessage("修改优惠卷失败");
        }
        return resultData;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/query06.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "删除优惠卷查询接口",notes = "删除查询优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public ResultData query07(@RequestBody Coupon coupon){
        int result = couponService.query07(coupon);
        ResultData resultData = new ResultData();
        if(result > 0){
            resultData.setCode(Constant.CODE_STATUS_SUCCESS);
            resultData.setMessage("删除优惠卷成功");
        } else {
            resultData.setCode(Constant.CODE_STATUS_FAILURE);
            resultData.setMessage("删除优惠卷失败");
        }
        return resultData;
    }

    /**
     * 下拉框 动态获取
     */
    @RequestMapping(value = "/query07.do" ,method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "下拉框动态优惠卷接口",notes = "下拉框动态优惠卷相关信息",httpMethod = "post", response = ResultData.class)
    public List<Coupon> query08(@RequestBody Coupon coupon){
        List<Coupon> list = couponService.query08(coupon);
        return list;
    }
}
